#ifndef YUVOPENGLWIDGET_H
#define YUVOPENGLWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>

QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
QT_FORWARD_DECLARE_CLASS(QOpenGLTexture)

struct AVFrame;
class FVideoDecode;
class RTSP;
class YUVOpenGLWidget : public QOpenGLWidget
    , protected QOpenGLFunctions
{
    Q_OBJECT
public:
    YUVOpenGLWidget(QWidget *parent = nullptr);
    ~YUVOpenGLWidget();

public slots:
    void slotShowYuv(AVFrame *pAVFrame); //显示一帧Yuv图像

protected:
    virtual void initializeGL();
    virtual void resizeGL(int w, int h);
    virtual void paintGL();

private:
    void updateVertBuffer();

private:
    QOpenGLShaderProgram *program;
    QOpenGLBuffer vbo;
    GLuint textureUniformY, textureUniformU, textureUniformV; //opengl中y、u、v分量位置
    QOpenGLTexture *textureY = nullptr, *textureU = nullptr, *textureV = nullptr;
    GLuint idY, idU, idV; //自己创建的纹理对象ID，创建错误返回0
    uint videoW {0};
    uint videoH {0};
    AVFrame *frame {nullptr};
    GLfloat vertices[16];

    RTSP *m_rtsp {nullptr};
    FVideoDecode *m_videoDecode {nullptr};
};

#endif // YUVOPENGLWIDGET_H
